package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmChannelDto;
import com.heima.model.wemedia.dtos.WmChannelPageReqDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/v1/channel")
public class WmChannelController {
    @Autowired
    private WmChannelService wmChannelService;

    //频道查询
    @GetMapping("channels")
    public ResponseResult findAll() {

        return ResponseResult.okResult(wmChannelService.list());
    }

    @PostMapping("save")
    public ResponseResult saveChannel(@RequestBody WmChannelDto dto) {
        WmChannel wmChannel = new WmChannel();
        BeanUtils.copyProperties(dto, wmChannel);

        return wmChannelService.saveChannel(wmChannel);
    }

    @PostMapping("list")
    public ResponseResult find(@RequestBody WmChannelPageReqDto dto) {
        return wmChannelService.findList(dto);
    }

    @PostMapping("update")
    public ResponseResult update(@RequestBody WmChannelDto dto) {
        return wmChannelService.updateChannel(dto);
    }

    @GetMapping("/del/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        return wmChannelService.del(id);
    }

}
